package com.sky.controller.admin;
/*
@author sun
@date 24/07/15
@project IntelliJ IDEA
*/

import com.sky.result.Result;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

// 店铺的营业接口
@Slf4j
@RequestMapping("/admin/shop")
@RestController
public class ShopController {

    private static final String KEY  = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ShopService shopService;
    // TODO 设置店铺的营业状态
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态为:{}",status == 1 ? "营业中" : "打样了");
        redisTemplate.opsForValue().set(KEY, status);
        return Result.success();
    }

    // TODO 获取店铺的营业状态
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺的营业状态为:{}",status == 1 ? "营业中" : "打样了");
        return Result.success(status);
    }

}
